package club.kingyin.easycache.component.handler;

import club.kingyin.easycache.component.ExceptionCacheHandler;
import club.kingyin.easycache.component.ExceptionFilter;
import club.kingyin.easycache.exception.InvokeException;
import club.kingyin.easycache.method.CacheMethod;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class IgnoreExceptionHandler extends ExceptionCacheHandler implements ExceptionFilter {
    @Override
    protected boolean filter(CacheMethod invocation, InvokeException e) {
        // 无视异常，仍要写入缓存
        log.warn("方法：[{}] 异常并写入缓存 {}", invocation.getMethod().getName(),e.getMessage());
        return true;
    }

    @Override
    protected Object unusualResultConversion(CacheMethod invocation, InvokeException e) {
        return e;
    }

    @Override
    public boolean filter(InvokeException e) {
        return true;
    }
}
